//
//  ThumbMessageViewController.m
//  xxShare
//
//  Created by 柳麟喆 on 2018/4/1.
//  Copyright © 2018年 lzLiu. All rights reserved.
//

#import "ThumbMessageViewController.h"
#import "OneFeedViewController.h"
#import "MessageCell.h"
#import "MessageModel.h"

@interface ThumbMessageViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableview;

@property (nonatomic, copy)NSMutableArray *testData;

@end

@implementation ThumbMessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.llz_width, self.view.llz_height) style:UITableViewStyleGrouped];
    _tableview.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
    _tableview.sectionFooterHeight = 1;
    _tableview.dataSource = self;
    _tableview.delegate = self;
    _tableview.backgroundColor = BACKGROUND_COLOR;
    [self.view addSubview:_tableview];
    [_tableview registerNib:[UINib nibWithNibName:@"MessageCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MessageCell"];
    
    _testData = [[NSMutableArray alloc]init];
    _testData = [self addTestData];
}

#pragma mark - *******tableviewDelegate dataSource*******

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    static NSString *identify = @"MessageCell";
    MessageCell *cell = [tableView dequeueReusableCellWithIdentifier:identify forIndexPath:indexPath];
    [cell setModel:_testData[indexPath.row]];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _testData.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView cellForRowAtIndexPath:indexPath].selected = NO;
    OneFeedViewController *one = [[OneFeedViewController alloc]init];
    one.hidesBottomBarWhenPushed = YES;
    [self.parentViewController.navigationController pushViewController:one animated:YES];
}

#pragma mark - *******添加测试数据*******
- (NSMutableArray *)addTestData{
    NSMutableArray *Data = [[NSMutableArray alloc]init];
    NSArray *avatorArr = @[@"avator4.png",@"avator2.png",@"avator5.png",@"avator3.png"];
    NSArray *nameArr = @[@"叮当猫",@"哪吒",@"球球",@"可达鸭"];
    NSArray *timeArr = @[@"刚刚",@"2小时前",@"7小时前",@"1天前"];
    NSArray *replyArr = @[@"赞了我的作品",@"原创者奖金 + 32",@"赞了我的作品",@"发现者奖金 + 2"];
    NSArray *postArr = @[@"我的发表：西湖的音乐喷泉很不错哦！",@"我的发表：西湖的音乐喷泉很不错哦！",@"我的发表：西湖的音乐喷泉很不错哦！",@"赞了可达鸭的发表：西湖的音乐喷泉很不错哦！"];
    for (int i = 1; i < 5; i++) {
        NSDictionary* dic = @{
                              @"avator":avatorArr[i-1],
                              @"name":nameArr[i-1],
                              @"time":timeArr[i-1],
                              @"replyThumb":replyArr[i-1],
                              @"OriginalPost":postArr[i-1],
                              };
        MessageModel *model = [[MessageModel alloc]initWithMessageModel:dic];
        [Data addObject:model];
    }
    return Data;
}

@end
